#!/usr/bin/env bash

[ ! -d "$HOME/git/run/etc" ] && mkdir -p "$HOME/git/run/etc"
echo "etc dir is create by $0" > "$HOME/git/run/etc/readme.txt"
echo "create date: $(date)" >> "$HOME/git/run/etc/readme.txt"
pwdd_file="$HOME/git/run/etc/pwdd_file.data"
if [ ! -f $pwdd_file ] ;then
    touch $pwdd_file
fi
pwdd_cur_dir=`pwd`
#echo "current dir is: $pwdd_cur_dir"
delete_line_by_word()
{
    if [ `uname` == "Darwin" ];then
        sed -i '' "/[[:<:]]$1[[:>:]]/d" $2
    elif [ `uname` == "Linux" ];then
        sed -i "/\<$1\>/d" $2
    fi
}

if [ "$1" == "del" ];then
    delete_line_by_word "pwdd_tmp_dir_$2" $pwdd_file
elif [ "$1" == "delall" ];then
   cp /dev/null   $pwdd_file
else
    delete_line_by_word "pwdd_tmp_dir_$1" $pwdd_file
    printf "pwdd_tmp_dir_%s=%s\n" "$1" "$pwdd_cur_dir"  >> $pwdd_file

    sort -t '=' $pwdd_file -o $pwdd_file

fi

